<?php
class AjaxAction  extends Action  {

	public function main(){
		$ret = array();
		switch ($this->_request["action"]) {
			case 'logout':
				$this->__logout();
				break;
			case 'deletedata' :
				$this->__delData();
				break;
			case 'getRecordStatus' :
				$ret = $this->__getRecordStatus();
				break;
			case 'CheckRecordTime' :
				$ret = $this->__CheckRecordTime();
				break;
			default:
				# code...

				break;
		}
		//debug($ret);
		die(json_encode($ret));

	}

	private function __CheckRecordTime(){

		$dateTime="2010-06-04 00:00:00";
		$BeginTime = $this->_request['BeginTime'];
        $EndTime = $this->_request['EndTime'];
        $ChannelID = $this->_request['ChannelID'];
        $now = date("y-m-d h:i:s");
        //debug($now);
        $regx = "/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/s";
        if (preg_match($regx,$BeginTime) && preg_match($regx,$EndTime) && $BeginTime!='0000-00-00 00:00:00' &&$EndTime!='0000-00-00 00:00:00') {
        	if (strtotime($BeginTime) < strtotime($now) || strtotime($EndTime) < strtotime($now)){
        		return array("error"=>2);
        	}
        	if (strtotime($BeginTime)>=strtotime($EndTime) ){
        		return array("error"=>3);
        	}
        	$dao = new RecordTaskDAO();
        	if( $dao->checkRecord($BeginTime,$ChannelID) || $dao->checkRecord($BeginTime,$ChannelID)){
        		return array("error"=>4);
        	}else{
        		return array("error"=>5);
        	}

        	//debug(strtotime($BeginTime));
        	//debug(strtotime($EndTime));
        	//debug(strtotime($now));

        }else{
        	return array("error"=>1);
        }
		

	}

	private function __delData(){
		$objstr = $this->_request["deltype"].'DAO';
		$obj = new $objstr();
		return $obj->deldata($this->_request['id']);
	}

	private function __logout(){
		$login = new Login();
		$login->loginOut();
	}


	private function __getRecordStatus(){
		$ChannelID = $this->_request['ChannelID'];
		$task = new RecordTaskDAO();
		$selected = new Selected();
		$ret = $task->getListbyChannelID($ChannelID);
		if ($ret) {
			for ($i=0; $i < count($ret); $i++) { 
				$ret[$i]['TaskStatusShow'] = $selected->getVal("TaskStatus",$ret[$i]['TaskStatus']);
				$ret[$i]['ClassID'] = $classid;
			}
		}
		return $ret;

	}


}